<!DOCTYPE HTML>
<html lang="zh-Hans" class="sidebar-visible no-js light">
    <head>
        <!-- Book generated using mdBook -->
        <meta charset="UTF-8">
        <title>TypeScript 2.8 - TypeScript 使用指南手册</title>


        <!-- Custom HTML head -->
        
        <meta name="description" content="TypeScript Handbook 中文翻译。">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="theme-color" content="#ffffff" />

        <link rel="icon" href="../../favicon.svg">
        <link rel="shortcut icon" href="../../favicon.png">
        <link rel="stylesheet" href="../../css/variables.css">
        <link rel="stylesheet" href="../../css/general.css">
        <link rel="stylesheet" href="../../css/chrome.css">
        <link rel="stylesheet" href="../../css/print.css" media="print">

        <!-- Fonts -->
        <link rel="stylesheet" href="../../FontAwesome/css/font-awesome.css">
        <link rel="stylesheet" href="../../fonts/fonts.css">

        <!-- Highlight.js Stylesheets -->
        <link rel="stylesheet" href="../../highlight.css">
        <link rel="stylesheet" href="../../tomorrow-night.css">
        <link rel="stylesheet" href="../../ayu-highlight.css">

        <!-- Custom theme stylesheets -->

    </head>
    <body>
    <div id="body-container">
        <!-- Provide site root to javascript -->
        <script>
            var path_to_root = "../../";
            var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
        </script>

        <!-- Work around some values being stored in localStorage wrapped in quotes -->
        <script>
            try {
                var theme = localStorage.getItem('mdbook-theme');
                var sidebar = localStorage.getItem('mdbook-sidebar');

                if (theme.startsWith('"') && theme.endsWith('"')) {
                    localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
                }

                if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
                    localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
                }
            } catch (e) { }
        </script>

        <!-- Set the theme before any content is loaded, prevents flash -->
        <script>
            var theme;
            try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
            if (theme === null || theme === undefined) { theme = default_theme; }
            var html = document.querySelector('html');
            html.classList.remove('no-js')
            html.classList.remove('light')
            html.classList.add(theme);
            html.classList.add('js');
        </script>

        <!-- Hide / unhide sidebar before it is displayed -->
        <script>
            var html = document.querySelector('html');
            var sidebar = null;
            if (document.body.clientWidth >= 1080) {
                try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
                sidebar = sidebar || 'visible';
            } else {
                sidebar = 'hidden';
            }
            html.classList.remove('sidebar-visible');
            html.classList.add("sidebar-" + sidebar);
        </script>

        <nav id="sidebar" class="sidebar" aria-label="Table of contents">
            <div class="sidebar-scrollbox">
                <ol class="chapter"><li class="chapter-item expanded affix "><a href="../../PREFACE.html">前言</a></li><li class="chapter-item expanded affix "><li class="part-title">快速上手</li><li class="chapter-item expanded "><a href="../../zh/tutorials/index.html"><strong aria-hidden="true">1.</strong> 快速上手</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../../zh/tutorials/typescript-in-5-minutes.html"><strong aria-hidden="true">1.1.</strong> 5 分钟了解 TypeScript</a></li><li class="chapter-item expanded "><a href="../../zh/tutorials/asp.net-core.html"><strong aria-hidden="true">1.2.</strong> ASP.NET Core</a></li><li class="chapter-item expanded "><a href="../../zh/tutorials/asp.net-4.html"><strong aria-hidden="true">1.3.</strong> ASP.NET 4</a></li><li class="chapter-item expanded "><a href="../../zh/tutorials/gulp.html"><strong aria-hidden="true">1.4.</strong> Gulp</a></li><li class="chapter-item expanded "><a href="../../zh/tutorials/knockout.html"><strong aria-hidden="true">1.5.</strong> Knockout.js</a></li><li class="chapter-item expanded "><a href="../../zh/tutorials/react-and-webpack.html"><strong aria-hidden="true">1.6.</strong> React 与 webpack</a></li><li class="chapter-item expanded "><a href="../../zh/tutorials/react.html"><strong aria-hidden="true">1.7.</strong> React</a></li><li class="chapter-item expanded "><a href="../../zh/tutorials/angular-2.html"><strong aria-hidden="true">1.8.</strong> Angular 2</a></li><li class="chapter-item expanded "><a href="../../zh/tutorials/migrating-from-javascript.html"><strong aria-hidden="true">1.9.</strong> 从 JavaScript 迁移到 TypeScript</a></li></ol></li><li class="chapter-item expanded "><li class="part-title">手册</li><li class="chapter-item expanded "><a href="../../zh/handbook/index.html"><strong aria-hidden="true">2.</strong> 手册</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../../zh/handbook/basic-types.html"><strong aria-hidden="true">2.1.</strong> 基础类型</a></li><li class="chapter-item expanded "><a href="../../zh/handbook/interfaces.html"><strong aria-hidden="true">2.2.</strong> 接口</a></li><li class="chapter-item expanded "><a href="../../zh/handbook/functions.html"><strong aria-hidden="true">2.3.</strong> 函数</a></li><li class="chapter-item expanded "><a href="../../zh/handbook/literal-types.html"><strong aria-hidden="true">2.4.</strong> 字面量类型</a></li><li class="chapter-item expanded "><a href="../../zh/handbook/unions-and-intersections.html"><strong aria-hidden="true">2.5.</strong> 联合类型和交叉类型</a></li><li class="chapter-item expanded "><a href="../../zh/handbook/classes.html"><strong aria-hidden="true">2.6.</strong> 类</a></li><li class="chapter-item expanded "><a href="../../zh/handbook/enums.html"><strong aria-hidden="true">2.7.</strong> 枚举</a></li><li class="chapter-item expanded "><a href="../../zh/handbook/generics.html"><strong aria-hidden="true">2.8.</strong> 泛型</a></li></ol></li><li class="chapter-item expanded "><li class="part-title">手册（进阶）</li><li class="chapter-item expanded "><a href="../../zh/reference/index.html"><strong aria-hidden="true">3.</strong> 手册（进阶）</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../../zh/reference/advanced-types.html"><strong aria-hidden="true">3.1.</strong> 高级类型</a></li><li class="chapter-item expanded "><a href="../../zh/reference/utility-types.html"><strong aria-hidden="true">3.2.</strong> 实用工具类型</a></li><li class="chapter-item expanded "><a href="../../zh/reference/decorators.html"><strong aria-hidden="true">3.3.</strong> Decorators</a></li><li class="chapter-item expanded "><a href="../../zh/reference/declaration-merging.html"><strong aria-hidden="true">3.4.</strong> 声明合并</a></li><li class="chapter-item expanded "><a href="../../zh/reference/iterators-and-generators.html"><strong aria-hidden="true">3.5.</strong> Iterators 和 Generators</a></li><li class="chapter-item expanded "><a href="../../zh/reference/jsx.html"><strong aria-hidden="true">3.6.</strong> JSX</a></li><li class="chapter-item expanded "><a href="../../zh/reference/mixins.html"><strong aria-hidden="true">3.7.</strong> 混入</a></li><li class="chapter-item expanded "><a href="../../zh/reference/modules.html"><strong aria-hidden="true">3.8.</strong> 模块</a></li><li class="chapter-item expanded "><a href="../../zh/reference/module-resolution.html"><strong aria-hidden="true">3.9.</strong> 模块解析</a></li><li class="chapter-item expanded "><a href="../../zh/reference/namespaces.html"><strong aria-hidden="true">3.10.</strong> 命名空间</a></li><li class="chapter-item expanded "><a href="../../zh/reference/namespaces-and-modules.html"><strong aria-hidden="true">3.11.</strong> 命名空间和模块</a></li><li class="chapter-item expanded "><a href="../../zh/reference/symbols.html"><strong aria-hidden="true">3.12.</strong> Symbols</a></li><li class="chapter-item expanded "><a href="../../zh/reference/triple-slash-directives.html"><strong aria-hidden="true">3.13.</strong> 三斜线指令</a></li><li class="chapter-item expanded "><a href="../../zh/reference/type-compatibility.html"><strong aria-hidden="true">3.14.</strong> 类型兼容性</a></li><li class="chapter-item expanded "><a href="../../zh/reference/type-inference.html"><strong aria-hidden="true">3.15.</strong> 类型推论</a></li><li class="chapter-item expanded "><a href="../../zh/reference/variable-declarations.html"><strong aria-hidden="true">3.16.</strong> 变量声明</a></li></ol></li><li class="chapter-item expanded "><li class="part-title">手册（v2）</li><li class="chapter-item expanded "><a href="../../zh/handbook-v2/index.html"><strong aria-hidden="true">4.</strong> 手册（v2）</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../../zh/handbook-v2/type-manipulation/template-literal-types.html"><strong aria-hidden="true">4.1.</strong> 模版字面量类型</a></li></ol></li><li class="chapter-item expanded "><li class="part-title">TypeScript 声明文件（.d.ts）</li><li class="chapter-item expanded "><a href="../../zh/declaration-files/index.html"><strong aria-hidden="true">5.</strong> 如何书写声明文件</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../../zh/declaration-files/introduction.html"><strong aria-hidden="true">5.1.</strong> 介绍</a></li><li class="chapter-item expanded "><a href="../../zh/declaration-files/by-example.html"><strong aria-hidden="true">5.2.</strong> 举例</a></li><li class="chapter-item expanded "><a href="../../zh/declaration-files/library-structures.html"><strong aria-hidden="true">5.3.</strong> 库结构</a></li><li class="chapter-item expanded "><a href="../../zh/declaration-files/templates.html"><strong aria-hidden="true">5.4.</strong> 模板</a></li><li class="chapter-item expanded "><a href="../../zh/declaration-files/do-s-and-don-ts.html"><strong aria-hidden="true">5.5.</strong> 最佳实践</a></li><li class="chapter-item expanded "><a href="../../zh/declaration-files/deep-dive.html"><strong aria-hidden="true">5.6.</strong> 深入</a></li><li class="chapter-item expanded "><a href="../../zh/declaration-files/publishing.html"><strong aria-hidden="true">5.7.</strong> 发布</a></li><li class="chapter-item expanded "><a href="../../zh/declaration-files/consumption.html"><strong aria-hidden="true">5.8.</strong> 使用</a></li></ol></li><li class="chapter-item expanded "><li class="part-title">TypeScript for JavaScript</li><li class="chapter-item expanded "><a href="../../zh/javascript/type-checking-javascript-files.html"><strong aria-hidden="true">6.</strong> JavaScript 文件里的类型检查</a></li><li class="chapter-item expanded affix "><li class="part-title">工程配置</li><li class="chapter-item expanded "><a href="../../zh/project-config/index.html"><strong aria-hidden="true">7.</strong> 工程配置</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../../zh/project-config/tsconfig.json.html"><strong aria-hidden="true">7.1.</strong> tsconfig.json</a></li><li class="chapter-item expanded "><a href="../../zh/project-config/project-references.html"><strong aria-hidden="true">7.2.</strong> 工程引用</a></li><li class="chapter-item expanded "><a href="../../zh/project-config/typings-for-npm-packages.html"><strong aria-hidden="true">7.3.</strong> NPM 包的类型</a></li><li class="chapter-item expanded "><a href="../../zh/project-config/compiler-options.html"><strong aria-hidden="true">7.4.</strong> 编译选项</a></li><li class="chapter-item expanded "><a href="../../zh/project-config/configuring-watch.html"><strong aria-hidden="true">7.5.</strong> 配置 Watch</a></li><li class="chapter-item expanded "><a href="../../zh/project-config/compiler-options-in-msbuild.html"><strong aria-hidden="true">7.6.</strong> 在 MSBuild 里使用编译选项</a></li><li class="chapter-item expanded "><a href="../../zh/project-config/integrating-with-build-tools.html"><strong aria-hidden="true">7.7.</strong> 与其它构建工具整合</a></li><li class="chapter-item expanded "><a href="../../zh/project-config/nightly-builds.html"><strong aria-hidden="true">7.8.</strong> 使用 TypeScript 的每日构建版本</a></li></ol></li><li class="chapter-item expanded "><li class="part-title">版本发布说明（Release Notes）</li><li class="chapter-item expanded "><a href="../../zh/release-notes/index.html"><strong aria-hidden="true">8.</strong> 新增功能</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-5.1.html"><strong aria-hidden="true">8.1.</strong> TypeScript 5.1</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-5.0.html"><strong aria-hidden="true">8.2.</strong> TypeScript 5.0</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-4.9.html"><strong aria-hidden="true">8.3.</strong> TypeScript 4.9</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-4.8.html"><strong aria-hidden="true">8.4.</strong> TypeScript 4.8</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-4.7.html"><strong aria-hidden="true">8.5.</strong> TypeScript 4.7</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-4.6.html"><strong aria-hidden="true">8.6.</strong> TypeScript 4.6</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-4.5.html"><strong aria-hidden="true">8.7.</strong> TypeScript 4.5</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-4.4.html"><strong aria-hidden="true">8.8.</strong> TypeScript 4.4</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-4.3.html"><strong aria-hidden="true">8.9.</strong> TypeScript 4.3</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-4.2.html"><strong aria-hidden="true">8.10.</strong> TypeScript 4.2</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-4.1.html"><strong aria-hidden="true">8.11.</strong> TypeScript 4.1</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-4.0.html"><strong aria-hidden="true">8.12.</strong> TypeScript 4.0</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-3.9.html"><strong aria-hidden="true">8.13.</strong> TypeScript 3.9</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-3.8.html"><strong aria-hidden="true">8.14.</strong> TypeScript 3.8</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-3.7.html"><strong aria-hidden="true">8.15.</strong> TypeScript 3.7</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-3.6.html"><strong aria-hidden="true">8.16.</strong> TypeScript 3.6</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-3.5.html"><strong aria-hidden="true">8.17.</strong> TypeScript 3.5</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-3.4.html"><strong aria-hidden="true">8.18.</strong> TypeScript 3.4</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-3.3.html"><strong aria-hidden="true">8.19.</strong> TypeScript 3.3</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-3.2.html"><strong aria-hidden="true">8.20.</strong> TypeScript 3.2</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-3.1.html"><strong aria-hidden="true">8.21.</strong> TypeScript 3.1</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-3.0.html"><strong aria-hidden="true">8.22.</strong> TypeScript 3.0</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-2.9.html"><strong aria-hidden="true">8.23.</strong> TypeScript 2.9</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-2.8.html" class="active"><strong aria-hidden="true">8.24.</strong> TypeScript 2.8</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-2.7.html"><strong aria-hidden="true">8.25.</strong> TypeScript 2.7</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-2.6.html"><strong aria-hidden="true">8.26.</strong> TypeScript 2.6</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-2.5.html"><strong aria-hidden="true">8.27.</strong> TypeScript 2.5</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-2.4.html"><strong aria-hidden="true">8.28.</strong> TypeScript 2.4</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-2.3.html"><strong aria-hidden="true">8.29.</strong> TypeScript 2.3</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-2.2.html"><strong aria-hidden="true">8.30.</strong> TypeScript 2.2</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-2.1.html"><strong aria-hidden="true">8.31.</strong> TypeScript 2.1</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-2.0.html"><strong aria-hidden="true">8.32.</strong> TypeScript 2.0</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-1.8.html"><strong aria-hidden="true">8.33.</strong> TypeScript 1.8</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-1.7.html"><strong aria-hidden="true">8.34.</strong> TypeScript 1.7</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-1.6.html"><strong aria-hidden="true">8.35.</strong> TypeScript 1.6</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-1.5.html"><strong aria-hidden="true">8.36.</strong> TypeScript 1.5</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-1.4.html"><strong aria-hidden="true">8.37.</strong> TypeScript 1.4</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-1.3.html"><strong aria-hidden="true">8.38.</strong> TypeScript 1.3</a></li><li class="chapter-item expanded "><a href="../../zh/release-notes/typescript-1.1.html"><strong aria-hidden="true">8.39.</strong> TypeScript 1.1</a></li></ol></li><li class="chapter-item expanded "><li class="part-title">破坏性改动（Breaking Changes）</li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/index.html"><strong aria-hidden="true">9.</strong> Breaking Changes</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-3.6.html"><strong aria-hidden="true">9.1.</strong> TypeScript 3.6</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-3.5.html"><strong aria-hidden="true">9.2.</strong> TypeScript 3.5</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-3.4.html"><strong aria-hidden="true">9.3.</strong> TypeScript 3.4</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-3.2.html"><strong aria-hidden="true">9.4.</strong> TypeScript 3.2</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-3.1.html"><strong aria-hidden="true">9.5.</strong> TypeScript 3.1</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-3.0.html"><strong aria-hidden="true">9.6.</strong> TypeScript 3.0</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-2.9.html"><strong aria-hidden="true">9.7.</strong> TypeScript 2.9</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-2.8.html"><strong aria-hidden="true">9.8.</strong> TypeScript 2.8</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-2.7.html"><strong aria-hidden="true">9.9.</strong> TypeScript 2.7</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-2.6.html"><strong aria-hidden="true">9.10.</strong> TypeScript 2.6</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-2.4.html"><strong aria-hidden="true">9.11.</strong> TypeScript 2.4</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-2.3.html"><strong aria-hidden="true">9.12.</strong> TypeScript 2.3</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-2.2.html"><strong aria-hidden="true">9.13.</strong> TypeScript 2.2</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-2.1.html"><strong aria-hidden="true">9.14.</strong> TypeScript 2.1</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-2.0.html"><strong aria-hidden="true">9.15.</strong> TypeScript 2.0</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-1.8.html"><strong aria-hidden="true">9.16.</strong> TypeScript 1.8</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-1.7.html"><strong aria-hidden="true">9.17.</strong> TypeScript 1.7</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-1.6.html"><strong aria-hidden="true">9.18.</strong> TypeScript 1.6</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-1.5.html"><strong aria-hidden="true">9.19.</strong> TypeScript 1.5</a></li><li class="chapter-item expanded "><a href="../../zh/breaking-changes/typescript-1.4.html"><strong aria-hidden="true">9.20.</strong> TypeScript 1.4</a></li></ol></li></ol>
            </div>
            <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
        </nav>

        <div id="page-wrapper" class="page-wrapper">

            <div class="page">
                                <div id="menu-bar-hover-placeholder"></div>
                <div id="menu-bar" class="menu-bar sticky bordered">
                    <div class="left-buttons">
                        <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
                            <i class="fa fa-bars"></i>
                        </button>
                        <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
                            <i class="fa fa-paint-brush"></i>
                        </button>
                        <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
                            <li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
                        </ul>
                        <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
                            <i class="fa fa-search"></i>
                        </button>
                    </div>

                    <h1 class="menu-title">TypeScript 使用指南手册</h1>

                    <div class="right-buttons">
                        <a href="../../print.html" title="Print this book" aria-label="Print this book">
                            <i id="print-button" class="fa fa-print"></i>
                        </a>

                    </div>
                </div>

                <div id="search-wrapper" class="hidden">
                    <form id="searchbar-outer" class="searchbar-outer">
                        <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
                    </form>
                    <div id="searchresults-outer" class="searchresults-outer hidden">
                        <div id="searchresults-header" class="searchresults-header"></div>
                        <ul id="searchresults">
                        </ul>
                    </div>
                </div>

                <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
                <script>
                    document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
                    document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
                    Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
                        link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
                    });
                </script>

                <div id="content" class="content">
                    <main>
                        <h1 id="typescript-28"><a class="header" href="#typescript-28">TypeScript 2.8</a></h1>
<h2 id="有条件类型"><a class="header" href="#有条件类型">有条件类型</a></h2>
<p>TypeScript 2.8引入了_有条件类型_，它能够表示非统一的类型。 有条件的类型会以一个条件表达式进行类型关系检测，从而在两种类型中选择其一：</p>
<pre><code class="language-typescript">T extends U ? X : Y
</code></pre>
<p>上面的类型意思是，若<code>T</code>能够赋值给<code>U</code>，那么类型是<code>X</code>，否则为<code>Y</code>。</p>
<p>有条件的类型<code>T extends U ? X : Y</code>或者_解析_为<code>X</code>，或者_解析_为<code>Y</code>，再或者_延迟_解析，因为它可能依赖一个或多个类型变量。 是否直接解析或推迟取决于：</p>
<ul>
<li>首先，令<code>T'</code>和<code>U'</code>分别为<code>T</code>和<code>U</code>的实例，并将所有类型参数替换为<code>any</code>，如果<code>T'</code>不能赋值给<code>U'</code>，则将有条件的类型解析成<code>Y</code>。直观上讲，如果最宽泛的<code>T</code>的实例不能赋值给最宽泛的<code>U</code>的实例，那么我们就可以断定不存在可以赋值的实例，因此可以解析为<code>Y</code>。</li>
<li>其次，针对每个在<code>U</code>内由<code>推断</code>声明引入的类型变量，依据从<code>T</code>推断到<code>U</code>来收集一组候选类型（使用与泛型函数类型推断相同的推断算法）。对于给定的<code>推断</code>类型变量<code>V</code>，如果有候选类型是从协变的位置上推断出来的，那么<code>V</code>的类型是那些候选类型的联合。反之，如果有候选类型是从逆变的位置上推断出来的，那么<code>V</code>的类型是那些候选类型的交叉类型。否则<code>V</code>的类型是<code>never</code>。</li>
<li>然后，令<code>T''</code>为<code>T</code>的一个实例，所有<code>推断</code>的类型变量用上一步的推断结果替换，如果<code>T''</code>_明显可赋值_给<code>U</code>，那么将有条件的类型解析为<code>X</code>。除去不考虑类型变量的限制之外，_明显可赋值_的关系与正常的赋值关系一致。直观上，当一个类型明显可赋值给另一个类型，我们就能够知道它可以赋值给那些类型的_所有_实例。</li>
<li>否则，这个条件依赖于一个或多个类型变量，有条件的类型解析被推迟进行。</li>
</ul>
<h4 id="例子"><a class="header" href="#例子">例子</a></h4>
<pre><code class="language-typescript">type TypeName&lt;T&gt; =
    T extends string ? &quot;string&quot; :
    T extends number ? &quot;number&quot; :
    T extends boolean ? &quot;boolean&quot; :
    T extends undefined ? &quot;undefined&quot; :
    T extends Function ? &quot;function&quot; :
    &quot;object&quot;;

type T0 = TypeName&lt;string&gt;;  // &quot;string&quot;
type T1 = TypeName&lt;&quot;a&quot;&gt;;  // &quot;string&quot;
type T2 = TypeName&lt;true&gt;;  // &quot;boolean&quot;
type T3 = TypeName&lt;() =&gt; void&gt;;  // &quot;function&quot;
type T4 = TypeName&lt;string[]&gt;;  // &quot;object&quot;
</code></pre>
<h3 id="分布式有条件类型"><a class="header" href="#分布式有条件类型">分布式有条件类型</a></h3>
<p>如果有条件类型里待检查的类型是<code>naked type parameter</code>，那么它也被称为“分布式有条件类型”。 分布式有条件类型在实例化时会自动分发成联合类型。 例如，实例化<code>T extends U ? X : Y</code>，<code>T</code>的类型为<code>A | B | C</code>，会被解析为<code>(A extends U ? X : Y) | (B extends U ? X : Y) | (C extends U ? X : Y)</code>。</p>
<h4 id="例子-1"><a class="header" href="#例子-1">例子</a></h4>
<pre><code class="language-typescript">type T10 = TypeName&lt;string | (() =&gt; void)&gt;;  // &quot;string&quot; | &quot;function&quot;
type T12 = TypeName&lt;string | string[] | undefined&gt;;  // &quot;string&quot; | &quot;object&quot; | &quot;undefined&quot;
type T11 = TypeName&lt;string[] | number[]&gt;;  // &quot;object&quot;
</code></pre>
<p>在<code>T extends U ? X : Y</code>的实例化里，对<code>T</code>的引用被解析为联合类型的一部分（比如，<code>T</code>指向某一单个部分，在有条件类型分布到联合类型之后）。 此外，在<code>X</code>内对<code>T</code>的引用有一个附加的类型参数约束<code>U</code>（例如，<code>T</code>被当成在<code>X</code>内可赋值给<code>U</code>）。</p>
<h4 id="例子-2"><a class="header" href="#例子-2">例子</a></h4>
<pre><code class="language-typescript">type BoxedValue&lt;T&gt; = { value: T };
type BoxedArray&lt;T&gt; = { array: T[] };
type Boxed&lt;T&gt; = T extends any[] ? BoxedArray&lt;T[number]&gt; : BoxedValue&lt;T&gt;;

type T20 = Boxed&lt;string&gt;;  // BoxedValue&lt;string&gt;;
type T21 = Boxed&lt;number[]&gt;;  // BoxedArray&lt;number&gt;;
type T22 = Boxed&lt;string | number[]&gt;;  // BoxedValue&lt;string&gt; | BoxedArray&lt;number&gt;;
</code></pre>
<p>注意在<code>Boxed&lt;T&gt;</code>的<code>true</code>分支里，<code>T</code>有个额外的约束<code>any[]</code>，因此它适用于<code>T[number]</code>数组元素类型。同时也注意一下有条件类型是如何分布成联合类型的。</p>
<p>有条件类型的分布式的属性可以方便地用来_过滤_联合类型：</p>
<pre><code class="language-typescript">type Diff&lt;T, U&gt; = T extends U ? never : T;  // Remove types from T that are assignable to U
type Filter&lt;T, U&gt; = T extends U ? T : never;  // Remove types from T that are not assignable to U

type T30 = Diff&lt;&quot;a&quot; | &quot;b&quot; | &quot;c&quot; | &quot;d&quot;, &quot;a&quot; | &quot;c&quot; | &quot;f&quot;&gt;;  // &quot;b&quot; | &quot;d&quot;
type T31 = Filter&lt;&quot;a&quot; | &quot;b&quot; | &quot;c&quot; | &quot;d&quot;, &quot;a&quot; | &quot;c&quot; | &quot;f&quot;&gt;;  // &quot;a&quot; | &quot;c&quot;
type T32 = Diff&lt;string | number | (() =&gt; void), Function&gt;;  // string | number
type T33 = Filter&lt;string | number | (() =&gt; void), Function&gt;;  // () =&gt; void

type NonNullable&lt;T&gt; = Diff&lt;T, null | undefined&gt;;  // Remove null and undefined from T

type T34 = NonNullable&lt;string | number | undefined&gt;;  // string | number
type T35 = NonNullable&lt;string | string[] | null | undefined&gt;;  // string | string[]

function f1&lt;T&gt;(x: T, y: NonNullable&lt;T&gt;) {
    x = y;  // Ok
    y = x;  // Error
}

function f2&lt;T extends string | undefined&gt;(x: T, y: NonNullable&lt;T&gt;) {
    x = y;  // Ok
    y = x;  // Error
    let s1: string = x;  // Error
    let s2: string = y;  // Ok
}
</code></pre>
<p>有条件类型与映射类型结合时特别有用：</p>
<pre><code class="language-typescript">type FunctionPropertyNames&lt;T&gt; = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T];
type FunctionProperties&lt;T&gt; = Pick&lt;T, FunctionPropertyNames&lt;T&gt;&gt;;

type NonFunctionPropertyNames&lt;T&gt; = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
type NonFunctionProperties&lt;T&gt; = Pick&lt;T, NonFunctionPropertyNames&lt;T&gt;&gt;;

interface Part {
    id: number;
    name: string;
    subparts: Part[];
    updatePart(newName: string): void;
}

type T40 = FunctionPropertyNames&lt;Part&gt;;  // &quot;updatePart&quot;
type T41 = NonFunctionPropertyNames&lt;Part&gt;;  // &quot;id&quot; | &quot;name&quot; | &quot;subparts&quot;
type T42 = FunctionProperties&lt;Part&gt;;  // { updatePart(newName: string): void }
type T43 = NonFunctionProperties&lt;Part&gt;;  // { id: number, name: string, subparts: Part[] }
</code></pre>
<p>与联合类型和交叉类型相似，有条件类型不允许递归地引用自己。比如下面的错误。</p>
<h4 id="例子-3"><a class="header" href="#例子-3">例子</a></h4>
<pre><code class="language-typescript">type ElementType&lt;T&gt; = T extends any[] ? ElementType&lt;T[number]&gt; : T;  // Error
</code></pre>
<h3 id="有条件类型中的类型推断"><a class="header" href="#有条件类型中的类型推断">有条件类型中的类型推断</a></h3>
<p>现在在有条件类型的<code>extends</code>子语句中，允许出现<code>infer</code>声明，它会引入一个待推断的类型变量。 这个推断的类型变量可以在有条件类型的true分支中被引用。 允许出现多个同类型变量的<code>infer</code>。</p>
<p>例如，下面代码会提取函数类型的返回值类型：</p>
<pre><code class="language-typescript">type ReturnType&lt;T&gt; = T extends (...args: any[]) =&gt; infer R ? R : any;
</code></pre>
<p>有条件类型可以嵌套来构成一系列的匹配模式，按顺序进行求值：</p>
<pre><code class="language-typescript">type Unpacked&lt;T&gt; =
    T extends (infer U)[] ? U :
    T extends (...args: any[]) =&gt; infer U ? U :
    T extends Promise&lt;infer U&gt; ? U :
    T;

type T0 = Unpacked&lt;string&gt;;  // string
type T1 = Unpacked&lt;string[]&gt;;  // string
type T2 = Unpacked&lt;() =&gt; string&gt;;  // string
type T3 = Unpacked&lt;Promise&lt;string&gt;&gt;;  // string
type T4 = Unpacked&lt;Promise&lt;string&gt;[]&gt;;  // Promise&lt;string&gt;
type T5 = Unpacked&lt;Unpacked&lt;Promise&lt;string&gt;[]&gt;&gt;;  // string
</code></pre>
<p>下面的例子解释了在协变位置上，同一个类型变量的多个候选类型会被推断为联合类型：</p>
<pre><code class="language-typescript">type Foo&lt;T&gt; = T extends { a: infer U, b: infer U } ? U : never;
type T10 = Foo&lt;{ a: string, b: string }&gt;;  // string
type T11 = Foo&lt;{ a: string, b: number }&gt;;  // string | number
</code></pre>
<p>相似地，在抗变位置上，同一个类型变量的多个候选类型会被推断为交叉类型：</p>
<pre><code class="language-typescript">type Bar&lt;T&gt; = T extends { a: (x: infer U) =&gt; void, b: (x: infer U) =&gt; void } ? U : never;
type T20 = Bar&lt;{ a: (x: string) =&gt; void, b: (x: string) =&gt; void }&gt;;  // string
type T21 = Bar&lt;{ a: (x: string) =&gt; void, b: (x: number) =&gt; void }&gt;;  // string &amp; number
</code></pre>
<p>当推断具有多个调用签名（例如函数重载类型）的类型时，用_最后_的签名（大概是最自由的包含所有情况的签名）进行推断。 无法根据参数类型列表来解析重载。</p>
<pre><code class="language-typescript">declare function foo(x: string): number;
declare function foo(x: number): string;
declare function foo(x: string | number): string | number;
type T30 = ReturnType&lt;typeof foo&gt;;  // string | number
</code></pre>
<p>无法在正常类型参数的约束子语句中使用<code>infer</code>声明：</p>
<pre><code class="language-typescript">type ReturnType&lt;T extends (...args: any[]) =&gt; infer R&gt; = R;  // 错误，不支持
</code></pre>
<p>但是，可以这样达到同样的效果，在约束里删掉类型变量，用有条件类型替换：</p>
<pre><code class="language-typescript">type AnyFunction = (...args: any[]) =&gt; any;
type ReturnType&lt;T extends AnyFunction&gt; = T extends (...args: any[]) =&gt; infer R ? R : any;
</code></pre>
<h3 id="预定义的有条件类型"><a class="header" href="#预定义的有条件类型">预定义的有条件类型</a></h3>
<p>TypeScript 2.8在<code>lib.d.ts</code>里增加了一些预定义的有条件类型：</p>
<ul>
<li><code>Exclude&lt;T, U&gt;</code> -- 从<code>T</code>中剔除可以赋值给<code>U</code>的类型。</li>
<li><code>Extract&lt;T, U&gt;</code> -- 提取<code>T</code>中可以赋值给<code>U</code>的类型。</li>
<li><code>NonNullable&lt;T&gt;</code> -- 从<code>T</code>中剔除<code>null</code>和<code>undefined</code>。</li>
<li><code>ReturnType&lt;T&gt;</code> -- 获取函数返回值类型。</li>
<li><code>InstanceType&lt;T&gt;</code> -- 获取构造函数类型的实例类型。</li>
</ul>
<h4 id="example"><a class="header" href="#example">Example</a></h4>
<pre><code class="language-typescript">type T00 = Exclude&lt;&quot;a&quot; | &quot;b&quot; | &quot;c&quot; | &quot;d&quot;, &quot;a&quot; | &quot;c&quot; | &quot;f&quot;&gt;;  // &quot;b&quot; | &quot;d&quot;
type T01 = Extract&lt;&quot;a&quot; | &quot;b&quot; | &quot;c&quot; | &quot;d&quot;, &quot;a&quot; | &quot;c&quot; | &quot;f&quot;&gt;;  // &quot;a&quot; | &quot;c&quot;

type T02 = Exclude&lt;string | number | (() =&gt; void), Function&gt;;  // string | number
type T03 = Extract&lt;string | number | (() =&gt; void), Function&gt;;  // () =&gt; void

type T04 = NonNullable&lt;string | number | undefined&gt;;  // string | number
type T05 = NonNullable&lt;(() =&gt; string) | string[] | null | undefined&gt;;  // (() =&gt; string) | string[]

function f1(s: string) {
    return { a: 1, b: s };
}

class C {
    x = 0;
    y = 0;
}

type T10 = ReturnType&lt;() =&gt; string&gt;;  // string
type T11 = ReturnType&lt;(s: string) =&gt; void&gt;;  // void
type T12 = ReturnType&lt;(&lt;T&gt;() =&gt; T)&gt;;  // {}
type T13 = ReturnType&lt;(&lt;T extends U, U extends number[]&gt;() =&gt; T)&gt;;  // number[]
type T14 = ReturnType&lt;typeof f1&gt;;  // { a: number, b: string }
type T15 = ReturnType&lt;any&gt;;  // any
type T16 = ReturnType&lt;never&gt;;  // any
type T17 = ReturnType&lt;string&gt;;  // Error
type T18 = ReturnType&lt;Function&gt;;  // Error

type T20 = InstanceType&lt;typeof C&gt;;  // C
type T21 = InstanceType&lt;any&gt;;  // any
type T22 = InstanceType&lt;never&gt;;  // any
type T23 = InstanceType&lt;string&gt;;  // Error
type T24 = InstanceType&lt;Function&gt;;  // Error
</code></pre>
<blockquote>
<p>注意：<code>Exclude</code>类型是<a href="https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458">建议的</a><code>Diff</code>类型的一种实现。我们使用<code>Exclude</code>这个名字是为了避免破坏已经定义了<code>Diff</code>的代码，并且我们感觉这个名字能更好地表达类型的语义。我们没有增加<code>Omit&lt;T, K&gt;</code>类型，因为它可以很容易的用<code>Pick&lt;T, Exclude&lt;keyof T, K&gt;&gt;</code>来表示。</p>
</blockquote>
<h2 id="改进对映射类型修饰符的控制"><a class="header" href="#改进对映射类型修饰符的控制">改进对映射类型修饰符的控制</a></h2>
<p>映射类型支持在属性上添加<code>readonly</code>或<code>?</code>修饰符，但是它们不支持_移除_修饰符。 这对于<a href="https://github.com/Microsoft/TypeScript/pull/12563"><em>同态映射类型</em></a>有些影响，因为同态映射类型默认保留底层类型的修饰符。</p>
<p>TypeScript 2.8为映射类型增加了增加或移除特定修饰符的能力。 特别地，映射类型里的<code>readonly</code>或<code>?</code>属性修饰符现在可以使用<code>+</code>或<code>-</code>前缀，来表示修饰符是添加还是移除。</p>
<h4 id="例子-4"><a class="header" href="#例子-4">例子</a></h4>
<pre><code class="language-typescript">type MutableRequired&lt;T&gt; = { -readonly [P in keyof T]-?: T[P] };  // 移除readonly和?
type ReadonlyPartial&lt;T&gt; = { +readonly [P in keyof T]+?: T[P] };  // 添加readonly和?
</code></pre>
<p>不带<code>+</code>或<code>-</code>前缀的修饰符与带<code>+</code>前缀的修饰符具有相同的作用。因此上面的<code>ReadonlyPartial&lt;T&gt;</code>类型与下面的一致</p>
<pre><code class="language-typescript">type ReadonlyPartial&lt;T&gt; = { readonly [P in keyof T]?: T[P] };  // 添加readonly和?
</code></pre>
<p>利用这个特性，<code>lib.d.ts</code>现在有了一个新的<code>Required&lt;T&gt;</code>类型。 它移除了<code>T</code>的所有属性的<code>?</code>修饰符，因此所有属性都是必需的。</p>
<h4 id="例子-5"><a class="header" href="#例子-5">例子</a></h4>
<pre><code class="language-typescript">type Required&lt;T&gt; = { [P in keyof T]-?: T[P] };
</code></pre>
<p>注意在<code>--strictNullChecks</code>模式下，当同态映射类型移除了属性底层类型的<code>?</code>修饰符，它同时也移除了那个属性上的<code>undefined</code>类型：</p>
<h4 id="例子-6"><a class="header" href="#例子-6">例子</a></h4>
<pre><code class="language-typescript">type Foo = { a?: string };  // 等同于 { a?: string | undefined }
type Bar = Required&lt;Foo&gt;;  // 等同于 { a: string }
</code></pre>
<h2 id="改进交叉类型上的keyof"><a class="header" href="#改进交叉类型上的keyof">改进交叉类型上的<code>keyof</code></a></h2>
<p>TypeScript 2.8作用于交叉类型的<code>keyof</code>被转换成作用于交叉成员的<code>keyof</code>的联合。 换句话说，<code>keyof (A &amp; B)</code>会被转换成<code>keyof A | keyof B</code>。 这个改动应该能够解决<code>keyof</code>表达式推断不一致的问题。</p>
<h4 id="例子-7"><a class="header" href="#例子-7">例子</a></h4>
<pre><code class="language-typescript">type A = { a: string };
type B = { b: string };

type T1 = keyof (A &amp; B);  // &quot;a&quot; | &quot;b&quot;
type T2&lt;T&gt; = keyof (T &amp; B);  // keyof T | &quot;b&quot;
type T3&lt;U&gt; = keyof (A &amp; U);  // &quot;a&quot; | keyof U
type T4&lt;T, U&gt; = keyof (T &amp; U);  // keyof T | keyof U
type T5 = T2&lt;A&gt;;  // &quot;a&quot; | &quot;b&quot;
type T6 = T3&lt;B&gt;;  // &quot;a&quot; | &quot;b&quot;
type T7 = T4&lt;A, B&gt;;  // &quot;a&quot; | &quot;b&quot;
</code></pre>
<h2 id="更好的处理js文件中的命名空间模式"><a class="header" href="#更好的处理js文件中的命名空间模式">更好的处理<code>.js</code>文件中的命名空间模式</a></h2>
<p>TypeScript 2.8加强了识别<code>.js</code>文件里的命名空间模式。 JavaScript顶层的空对象字面量声明，就像函数和类，会被识别成命名空间声明。</p>
<pre><code class="language-javascript">var ns = {};     // recognized as a declaration for a namespace `ns`
ns.constant = 1; // recognized as a declaration for var `constant`
</code></pre>
<p>顶层的赋值应该有一致的行为；也就是说，<code>var</code>或<code>const</code>声明不是必需的。</p>
<pre><code class="language-javascript">app = {}; // does NOT need to be `var app = {}`
app.C = class {
};
app.f = function() {
};
app.prop = 1;
</code></pre>
<h3 id="立即执行的函数表达式做为命名空间"><a class="header" href="#立即执行的函数表达式做为命名空间">立即执行的函数表达式做为命名空间</a></h3>
<p>立即执行的函数表达式返回一个函数，类或空的对象字面量，也会被识别为命名空间：</p>
<pre><code class="language-javascript">var C = (function () {
  function C(n) {
    this.p = n;
  }
  return C;
})();
C.staticProperty = 1;
</code></pre>
<h3 id="默认声明"><a class="header" href="#默认声明">默认声明</a></h3>
<p>“默认声明”允许引用了声明的名称的初始化器出现在逻辑或的左边：</p>
<pre><code class="language-javascript">my = window.my || {};
my.app = my.app || {};
</code></pre>
<h3 id="原型赋值"><a class="header" href="#原型赋值">原型赋值</a></h3>
<p>你可以把一个对象字面量直接赋值给原型属性。独立的原型赋值也可以：</p>
<pre><code class="language-typescript">var C = function (p) {
  this.p = p;
};
C.prototype = {
  m() {
    console.log(this.p);
  }
};
C.prototype.q = function(r) {
  return this.p === r;
};
</code></pre>
<h3 id="嵌套与合并声明"><a class="header" href="#嵌套与合并声明">嵌套与合并声明</a></h3>
<p>现在嵌套的层次不受限制，并且多文件之间的声明合并也没有问题。以前不是这样的。</p>
<pre><code class="language-javascript">var app = window.app || {};
app.C = class { };
</code></pre>
<h2 id="各文件的jsx工厂"><a class="header" href="#各文件的jsx工厂">各文件的JSX工厂</a></h2>
<p>TypeScript 2.8增加了使用<code>@jsx dom</code>指令为每个文件设置JSX工厂名。 JSX工厂也可以使用<code>--jsxFactory</code>编译参数设置（默认值为<code>React.createElement</code>）。TypeScript 2.8你可以基于文件进行覆写。</p>
<h4 id="例子-8"><a class="header" href="#例子-8">例子</a></h4>
<pre><code class="language-typescript">/** @jsx dom */
import { dom } from &quot;./renderer&quot;
&lt;h&gt;&lt;/h&gt;
</code></pre>
<p>生成：</p>
<pre><code class="language-javascript">var renderer_1 = require(&quot;./renderer&quot;);
renderer_1.dom(&quot;h&quot;, null);
</code></pre>
<h2 id="本地范围的jsx命名空间"><a class="header" href="#本地范围的jsx命名空间">本地范围的JSX命名空间</a></h2>
<p>JSX类型检查基于JSX命名空间里的定义，比如<code>JSX.Element</code>用于JSX元素的类型，<code>JSX.IntrinsicElements</code>用于内置的元素。 在TypeScript 2.8之前<code>JSX</code>命名空间被视为全局命名空间，并且一个工程只允许存在一个。 TypeScript 2.8开始，<code>JSX</code>命名空间将在<code>jsxNamespace</code>下面查找（比如<code>React</code>），允许在一次编译中存在多个jsx工厂。 为了向后兼容，全局的<code>JSX</code>命名空间被当做回退选项。 使用独立的<code>@jsx</code>指令，每个文件可以有自己的JSX工厂。</p>
<h2 id="新的--emitdeclarationsonly"><a class="header" href="#新的--emitdeclarationsonly">新的<code>--emitDeclarationsOnly</code></a></h2>
<p><code>--emitDeclarationsOnly</code>允许_仅_生成声明文件；使用这个标记<code>.js</code>/<code>.jsx</code>输出会被跳过。当使用其它的转换工具如Babel处理<code>.js</code>输出的时候，可以使用这个标记。</p>

                    </main>

                    <nav class="nav-wrapper" aria-label="Page navigation">
                        <!-- Mobile navigation buttons -->
                            <a rel="prev" href="../../zh/release-notes/typescript-2.9.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                                <i class="fa fa-angle-left"></i>
                            </a>

                            <a rel="next" href="../../zh/release-notes/typescript-2.7.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                                <i class="fa fa-angle-right"></i>
                            </a>

                        <div style="clear: both"></div>
                    </nav>
                </div>
            </div>

            <nav class="nav-wide-wrapper" aria-label="Page navigation">
                    <a rel="prev" href="../../zh/release-notes/typescript-2.9.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                        <i class="fa fa-angle-left"></i>
                    </a>

                    <a rel="next" href="../../zh/release-notes/typescript-2.7.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                        <i class="fa fa-angle-right"></i>
                    </a>
            </nav>

        </div>




        <script>
            window.playground_copyable = true;
        </script>


        <script src="../../elasticlunr.min.js"></script>
        <script src="../../mark.min.js"></script>
        <script src="../../searcher.js"></script>

        <script src="../../clipboard.min.js"></script>
        <script src="../../highlight.js"></script>
        <script src="../../book.js"></script>

        <!-- Custom JS scripts -->


    </div>
    </body>
</html>
